public class demo2 {
    public static int search(int[] nums, int target) {
        int left=0;
        int right=nums.length-1;
        int mid;
        if(nums.length==1) {
            return nums[0]==target?0:-1;
        }
        while(left<right) {
            mid=(left+right)>>>1;
            if (nums[mid] == target) return mid;
            if( nums[left]==target) {
                return left;
            }
            if(nums[right]==target) {
                return right;
            }
            if(nums[mid]-nums[left]==mid-left && nums[mid]>target && nums[left]<target) {
                right=mid-1;
            } else {
                if(nums[right]>target && nums[mid]<target) {
                    left=mid+1;
                } else {
                    right=mid-1;
                }
            }
        }
        return nums[left]==target?left:-1;
    }
    public static void main(String[] args) {
        search(new int[]{4,5,6,7,0,1,2},0);
    }
}
